﻿package cn.itamt.rChristmas {
	import cn.itamt.particles.SnowFlake;
	import cn.itamt.ui.base.TSprite;
	
	import flash.display.SimpleButton;
	import flash.events.Event;
	import flash.geom.Rectangle;
	import flash.net.URLRequest;
	import flash.net.navigateToURL;	

	public class rChristmas extends TSprite {
		public function rChristmas() {
			super();
		}

		var snowFlakes : Array; 
		var numFlakes : uint; 
		var screenArea : Rectangle; 
		public var url_btn:SimpleButton;

		override protected function onAdded() : void {
			url_btn.addEventListener('click', onCilckUrlBtn);
			
			snowFlakes = new Array(); 
			numFlakes = 70; 
			screenArea = new Rectangle(0, 0, 736, 138); 
			addEventListener(Event.ENTER_FRAME, frameLoop); 
		}
		
		private function onCilckUrlBtn(evt:Event):void{
			navigateToURL(new URLRequest('http://www.shoesflysky.com'), '_blank');
		}

		private function frameLoop(e : Event) : void {
	
			var snowflake : SnowFlake; 
			
			if(snowFlakes.length < numFlakes){
				snowflake = new SnowFlake(screenArea); 
				snowFlakes.push(snowflake); 
				addChild(snowflake); 
			}
			
			var wind : Number = ((screenArea.width / 2) - mouseX);
			wind /= 60; 
			for(var i : uint = 0;i < snowFlakes.length; i++) {
				snowflake = snowFlakes[i]; 
				snowflake.update(wind); 
			}
		}
	}
}